package com.example.basicquestions.questions.密码合法性验证;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * 密码要求:
 *
 * 1.长度超过8位
 *
 * 2.包括大小写字母.数字.其它符号,以上四种至少三种
 *
 * 3.不能有长度大于2的包含公共元素的子串重复 （注：其他符号不含空格或换行）
 *
 */
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) throws IOException {
//        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        Scanner in = new Scanner(System.in);
        StringBuffer sb = new StringBuffer();
        String input = "";
//        while ((input = in.readLine())!= null) { // 注意 while 处理多个 case
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String str = in.nextLine();

            if(str.length() < 9){
                sb.append("NG").append("\n");
                continue;
            }
            boolean[] flag = new boolean[4];
            for(int i = 0; i < str.length();i++){
                if('A' <= str.charAt(i) && str.charAt(i) <= 'Z'){
                    flag[0] = true;
                }else if('a' <= str.charAt(i) && str.charAt(i) <= 'z'){
                    flag[1] = true;
                }else if('0' <= str.charAt(i) && str.charAt(i) <= '9'){
                    flag[2] = true;
                }else{
                    flag[3] = true;
                }
            }
            int count = 0;
            for(int i = 0; i<4;i++){
                if(flag[i]){
                    count++;
                }
            }
            if(count <3){
                sb.append("NG").append("\n");
                continue;
            }
            boolean sing =true;
            char[] ch = str.toCharArray();
            //i != i+3  i+1!=i+4 i+2!=i+5
            for(int i = 0; i<ch.length-5;i++){
                for (int j = i+3;j<ch.length-2;j++){
                    if(ch[i] == ch[j] && ch[i+1] == ch[j+1] && ch[i+2] == ch[j+2]){
                        sing = false;
                    }
                }
            }
            if(!sing){
                sb.append("NG").append("\n");
                continue;
            }
            sb.append("OK").append("\n");
        }
        System.out.println(sb);
    }
}